package com.imy.common.view.recyclerview.adpater;

import android.app.Activity;
import android.view.ViewGroup;

import androidx.recyclerview.widget.RecyclerView;

import com.imy.common.view.recyclerview.DisplayableItem;
import com.imy.common.view.recyclerview.adapterdelegates.AdapterDelegate;
import com.imy.common.view.recyclerview.adapterdelegates.AdapterDelegatesManager;

import java.util.List;

/**
 * 混合适配器（没有上拉更多）
 *
 * @author: 黄一凡
 * @date: 2017-03-21
 */
public class BaseMixAdapter extends RecyclerView.Adapter {
  private AdapterDelegatesManager<List<DisplayableItem>> delegatesManager;
  private List<DisplayableItem> items;

  public BaseMixAdapter(Activity activity, List<DisplayableItem> items) {
    this.items = items;
    delegatesManager = new AdapterDelegatesManager<>();
  }

  protected void addDelegate(AdapterDelegate<List<DisplayableItem>> delegate) {
    delegatesManager.addDelegate(delegate);
  }

  @Override
  public int getItemViewType(int position) {
    return delegatesManager.getItemViewType(items, position);
  }

  @Override
  public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    return delegatesManager.onCreateViewHolder(parent, viewType);
  }

  @Override
  public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
    delegatesManager.onBindViewHolder(items, position, holder);
  }

  @Override
  public void onBindViewHolder(RecyclerView.ViewHolder holder, int position, List payloads) {
    delegatesManager.onBindViewHolder(items, position, holder, payloads);
  }

  @Override
  public int getItemCount() {
    return items.size();
  }
}
